package com.soft.security;

import org.springframework.dao.DataAccessException;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.transaction.annotation.Transactional;

import com.soft.support.UserSecurityService;

public class XyUserDetailServiceImpl implements UserDetailsService {
	private UserSecurityService userSecurityService;

	public UserSecurityService getUserSecurityService() {
		return userSecurityService;
	}

	public void setUserSecurityService(UserSecurityService userSecurityService) {
		this.userSecurityService = userSecurityService;
	}

	@Transactional
	public UserDetails loadUserByUsername(String username)
			throws UsernameNotFoundException, DataAccessException {
		User user = this.getUserSecurityService().getLoginUserInfo(username);
        if(user == null) {  
            throw new UsernameNotFoundException(username);  
        }  
        return user; 
	}
	
}
